﻿/*
--------------------------------------
File: HSVConvertor.cs
Project: Themaopdracht 7
Author: Maarten Kroon

Description:
Gets the hue, saturation and value of a RGB color
--------------------------------------
*/

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace THO7_Team8
{
    internal static class HSVConvertor
    {       
        public static float getHue(int b, int g, int r)
        {
            float blue = (float)b / 256;
            float green = (float)g / 256;
            float red = (float)r / 256;            

            float[] colorArray = new float[3];
            colorArray[0] = blue;
            colorArray[1] = green;
            colorArray[2] = red;
            Array.Sort(colorArray);
            float max = colorArray[2];
            float min = colorArray[0];
       
            //Hue conversion
            float hue = 0;
            if (blue == max)
            {
                hue = (4 + (red - green) / (max - min)) * 60;
            }
            else if (green == max)
            {
                hue = (2 + (blue - red) / (max - min)) * 60;
            }
            else if (red == max)
            {
                hue = (0 + (green - blue) / (max - min)) * 60;
            }
            hue = (int)Math.Round(hue);
            
            return hue;
        }
    }
}